package login.dao;

import com.mysql.jdbc.PreparedStatement;
import login.daomain.User;
import login.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementSetter;

/**
 * @Author Administrator
 * @Date 2020/5/29 9:20
 **/
public class UserDaoImpl implements UserDao {

    JdbcTemplate template=new JdbcTemplate(JDBCUtils.getDataSource());
    String sql="";


    @Override
    public User login(String name, String password) {
        String sql="select * from javawebUser where name=? and password=?";
        try {
            return template.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class),name,password);

        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int zhuCe(User user) {
        try {

            sql="insert * values(?,?) in javaUser ";
            return template.update(sql,user.getName(),user.getPassword());

        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }


}
